﻿Module ProjectAdministrator
    Public Sub save(ByRef project As Project)
        If (project.idProperty <> 0) Then
            update(project)
        Else
            insert(project)
        End If
    End Sub

    Private Sub insert(ByRef project As Project)
        ProjectDao.insert(project)
    End Sub

    Private Sub update(ByRef project As Project)
        project.getProjectState().update(project)
    End Sub

    Public Sub cancel(ByRef project As Project)
        project.getProjectState().cancel(project)
    End Sub

    Public Sub changeToInProcessState(ByRef project As Project)
        project.getProjectState().changeToInProcessState(project)
    End Sub

    Public Function searchDataByFilter(ByRef project As Project) As Data.DataTable
        Return ProjectDao.searchDataByFilter(project)
    End Function

    Public Function searchDataByFiltersSummary(ByRef project As Project) As Data.DataTable
        Return ProjectDao.searchDataByFilterSummary(project)
    End Function

    Public Function searchSummary() As Data.DataTable
        Return ProjectDao.searchDataByFilterSummary(New Project())
    End Function

    Public Function searchDataById(ByRef id As Integer) As Project
        Dim project As Project = ProjectDao.searchDataById(id)
        Return project
    End Function

    Public Function search() As Data.DataTable
        Return ProjectDao.searchDataByFilter(New Project())
    End Function

    Public Sub startProject(ByRef project As Project)
        updateProjectState(project)
    End Sub

    Public Sub cancelProject(ByRef project As Project)
        updateProjectState(project)
    End Sub
End Module
